package com.dragon.concurrent.demo.demo;

import java.util.ArrayList;
import java.util.List;

public class Subject {

    private int state;

    private List<OBServer> observers = new ArrayList<>();

    public int getState() {
        return state;
    }

    public void setState(int state) {
        if (this.state == state) {
            return;
        }
        this.state = state;
        notifyAllObServer();
    }

    public void attach(OBServer obServer) {
        this.observers.add(obServer);
    }

    public void notifyAllObServer() {
        observers.stream()
                .forEach(obServer -> obServer.update());
    }
}
